//
//  M1LikePairingVC.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/26.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1LikePairingVC.h"
#import "M1HomeModel.h"

@interface M1LikePairingVC ()

@end

@implementation M1LikePairingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.m1_hiddenNav = YES;
    
    UIImageView *bgImage = [[UIImageView alloc] init];
    bgImage.image = LOAD_LOCAL_IMG(@"personal_image_cerBgView");
    [self.view addSubview:bgImage];
    
    [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    [self m1_createUI];
    
}

- (void) m1_commitAction:(UIButton *)sender{
    
    NSMutableArray *array = [self.navigationController.viewControllers mutableCopy];
    if ([array[array.count - 3] isKindOfClass:[M1MessageViewController class]]) {
        [self.navigationController popToViewController:array[array.count - 3] animated:YES];
        return;
    }
    
    WEAKSELF;
    [M1User m1_userPermissionForm:self type:M1UserPermission_Chat to_uid:self.m1_model.basic.uid permission:^(NSDictionary *resDic) {
        [[EaseDataBase sharedDataBase] addMessage:[weakSelf.m1_model.basic.uid m1_MD5] uid:weakSelf.m1_model.basic.uid name:weakSelf.m1_model.basic.name avatar:self.m1_model.basic.avatar.img.url];
        M1MessageViewController *m1_messageVC = [[M1MessageViewController alloc] initWithConversationChatter:[weakSelf.m1_model.basic.uid m1_MD5] conversationType:EMConversationTypeChat];
        m1_messageVC.m1_uid = weakSelf.m1_model.basic.uid;
        m1_messageVC.title = weakSelf.m1_model.basic.name;
        m1_messageVC.hidesBottomBarWhenPushed = YES;
        m1_messageVC.isRemove = YES;
        [weakSelf.navigationController pushViewController:m1_messageVC animated:YES];

    }];
    
    
}

- (void) m1_backAction:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)m1_createUI{
    UILabel *title = [[UILabel alloc] init];
    title.text = @"祝贺你";
    title.textColor = m1_color(0xFFFFFF);
    title.font = m1_boldFont(25);
    [self.view addSubview:title];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(m1_NAV_HEIGHT + 50);
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    UILabel *content = [[UILabel alloc] init];
    content.text = [NSString stringWithFormat:@"你和%@相互喜欢了对方", self.m1_model.basic.name];
    content.textColor = m1_color(0xACACAB);
    content.font = m1_boldFont(16);
    content.numberOfLines = 0;
    content.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:content];
    
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(title.mas_bottom).offset(14);
        make.centerX.equalTo(self.view.mas_centerX);
        make.left.offset(20);
        make.right.offset(-20);
    }];
    
    UIImageView *myHead = [[UIImageView alloc] init];
    [myHead sd_setImageWithURL:[NSURL URLWithString:[M1User user].basic.avatar.img.url] placeholderImage:LOAD_LOCAL_IMG(@"bgView")];
    myHead.contentMode = UIViewContentModeScaleAspectFill;
    myHead.clipsToBounds = YES;
    [self.view addSubview:myHead];
    
    myHead.layer.cornerRadius = 140 / 2;
    myHead.layer.masksToBounds = YES;
    
    CGFloat X = (SCREENWIDTH - 140 * 2 - 19) / 2;
    [myHead mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(content.mas_bottom).offset(iPhone5?30:70);
        make.right.equalTo(self.view.mas_centerX).offset(-10);
        make.size.mas_equalTo(CGSizeMake(140, 140));
    }];
    
    UIImageView *yourHead = [[UIImageView alloc] init];
    [yourHead sd_setImageWithURL:[NSURL URLWithString:self.m1_model.basic.avatar.img.url] placeholderImage:LOAD_LOCAL_IMG(@"bgView")];
    yourHead.contentMode = UIViewContentModeScaleAspectFill;
    yourHead.clipsToBounds = YES;
    [self.view addSubview:yourHead];
    
    yourHead.layer.cornerRadius = 140 / 2;
    yourHead.layer.masksToBounds = YES;
    
    [yourHead mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(myHead.mas_centerY);
        make.left.equalTo(self.view.mas_centerX).offset(10);
        make.size.mas_equalTo(CGSizeMake(140, 140));
    }];
    
    UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [commitBtn setBackgroundImage:LOAD_LOCAL_IMG(@"btn_color") forState:UIControlStateNormal];
    [commitBtn setTitle:@"发送消息" forState:UIControlStateNormal];
    [commitBtn setTitleColor:m1_color(0xFFFFFF) forState:UIControlStateNormal];
    commitBtn.titleLabel.font = m1_font(18);
    [commitBtn addTarget:self action:@selector(m1_commitAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:commitBtn];
    
    commitBtn.layer.cornerRadius = 55 / 2;
    commitBtn.layer.masksToBounds = YES;
    
    [commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(myHead.mas_bottom).offset(iPhone5?50:80);
        make.size.mas_equalTo(CGSizeMake(170, 55));
    }];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.backgroundColor = [UIColor clearColor];
    [backBtn setTitle:@"继续寻Ta" forState:UIControlStateNormal];
    [backBtn setTitleColor:m1_color(0xFFFFFF) forState:UIControlStateNormal];
    backBtn.titleLabel.font = m1_font(18);
    [backBtn addTarget:self action:@selector(m1_backAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(commitBtn.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(170, 55));
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
